package com.wj.algorithm.lintcode;

public class P181 {
    public static int bitSwapRequired(int a, int b) {
        
        String as = Integer.toBinaryString(a);
        String bs = Integer.toBinaryString(b);
        int ai = 0;
        int bi = 0;
        
        int al = as.length();
        int bl = bs.length();
        int count = 0;
        if(al > bl) {
            ai = al - bl;
            for(int i = 0; i < ai; i ++) {
                if(as.charAt(i) == '1') {
                    count ++;
                }
            }
        } else if(bl > al) {
            bi = bl - al;
            for(int i = 0; i < bi; i ++) {
                if(bs.charAt(i) == '1') {
                    count ++;
                }
            }
        }
        
        while(ai < al && bi < bl) {
            if(as.charAt(ai) != bs.charAt(bi)) {
                count ++;
            }
            ai ++;
            bi ++;
        }
        
        return count;
    }
    
    public static void main(String[] args) {
        System.out.println(bitSwapRequired(67, 31));
    }
}
